package com.sskj.bibi.presenter;

import com.sskj.bibi.ui.fragment.PankouFragment;
import com.sskj.common.base.HttpData;
import com.sskj.lib.bean.CoinBean;
import com.sskj.lib.bean.WSFiveBean;
import com.sskj.lib.http.CallBackOption;

import java.util.ArrayList;
import java.util.List;


public class PankouFragmentPresenter extends BasePresenter<PankouFragment> {

    public void getProduct(String qu, String code) {
        httpService.getProduct(qu, code)
                .execute(new CallBackOption<HttpData<List<CoinBean>>>() {
                }.unLoadBind(mView)
                        .execute(httpData -> {
                            if (httpData.getData().size() > 0) {
                                mView.updateTitle(httpData.getData().get(0));
                            }
                        }));
    }

    public void getPankou(String code) {
        httpService.getPankou(code)
                .execute(new CallBackOption<HttpData<WSFiveBean>>() {
                }.unLoadBind(mView)
                .execute(httpData->{
                    if (httpData.getData() != null) {
                        WSFiveBean wsFiveBean = httpData.getData();
                        mView.updateFive(wsFiveBean);
                    } else {
                        WSFiveBean wsFiveBean = new WSFiveBean();
                        wsFiveBean.setCode(code);
                        wsFiveBean.setAsks(new ArrayList<>());
                        wsFiveBean.setBids(new ArrayList<>());
                        mView.updateFive(wsFiveBean);
                    }
                }));
    }

}
